/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServerGUI.java
 *
 * Created on 2011-04-09, 14:14:58
 */

package ServerGUI;
import Const.*;
/**
 *
 * @author cypek
 */
public class ServerGUI extends javax.swing.JFrame {


    private ServerGUIController serverGUIController;
    private ServerGUIListner guiListner;
    private ServerGUIsender guiSender;

    /**
     * Get the value of guiListner
     *
     * @return the value of guiListner
     */
    public ServerGUIListner getGuiListner() {
        return guiListner;
    }

    /**
     * Set the value of guiListner
     *
     * @param guiListner new value of guiListner
     */
    public void setGuiListner(ServerGUIListner guiListner) {
        this.guiListner = guiListner;
    }

    /**
     * Get the value of serverGUIController
     *
     * @return the value of serverGUIController
     */
    public ServerGUIController getServerGUIController() {
        return serverGUIController;
    }

    /**
     * Set the value of serverGUIController
     *
     * @param serverGUIController new value of serverGUIController
     */
    public void setServerGUIController(ServerGUIController serverGUIController) {
        this.serverGUIController = serverGUIController;
    }

    /** Creates new form ServerGUI */
    public ServerGUI(String hostname, int port) {
        //inicjacja kontrolera




        this.serverGUIController = new ServerGUIController(hostname,port);

        //inicjaja listnera
        this.guiListner = new ServerGUIListner(serverGUIController);
        new Thread(guiListner).start();

        this.guiSender = new ServerGUIsender(serverGUIController);
        new Thread(guiSender).start();

        //inicjacja komponentow
        initComponents();



        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        canvas1 = new ServerGUICanvas(serverGUIController);
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        exitMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        fileMenu.setText("File");

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(canvas1, javax.swing.GroupLayout.DEFAULT_SIZE, 690, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(canvas1, javax.swing.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    /**
    * @param args the command line arguments
    */

    public static void main(String args[]) {

        String hostname = "";
        int port = 0;

        if ( args.length < 1 ){
            hostname = "localhost";
        }
        else{
            hostname = args[0];
        }

        if ( args.length < 2 ){
            port = ServerConst.PortModule;
        }
        else{
            port = new Integer(args[1]);
        }
        System.out.println("hostname " + hostname + "\t port " + port);
        new ServerGUI(hostname, port).setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Canvas canvas1;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables

}
